package cfs.formbean;

import java.util.ArrayList;
import java.util.List;

import org.mybeans.form.FormBean;

public class BuyFundFormBean extends FormBean {

	private String name;
	private String symbol;
	private String price;// the price of this fund
	private String amount;// the amount money this user want to spend on this
							// fund
	private String cash;// this is how many balance this user have

	public String getName() {
		return name;
	}

	public String getSymbol() {
		return symbol;
	}

	public String getPrice() {
		return price;
	}

	public String getAmount() {
		return amount;
	}

	public String getCash() {
		return cash;
	}

	public void setName(String name) {
		this.name = name;
	}

	public void setSymbol(String symbol) {
		this.symbol = symbol;
	}

	public void setPrice(String price) {
		this.price = price;
	}

	public void setAmount(String amount) {
		this.amount = amount;
	}

	public void setCash(String cash) {
		this.cash = cash;
	}

	public List<String> getValidationErrors() {
		List<String> errors = new ArrayList<String>();

//		if (name == null || name.length() == 0) {
//			errors.add("name should not be empty");
//		}

		if (symbol == null || symbol.length() == 0) {
			errors.add("Symbol should not be empty");
		}

		if (amount == null || amount.length() == 0) {
			errors.add("Please Enter how much you want to buy in Dollars.");
		}

		// basic check
		if (errors.size() > 0)
			return errors;

		// further check
		try {
			double amountDollar = Double.parseDouble(amount);
			if (amountDollar <= 0) {
				errors.add("Please enter a positive amount");
			}
			int index = amount.lastIndexOf('.');
			if (index != -1 && amount.length() - index > 3) {
				errors.add("You can not specify more the two decimal");
			}

		} catch (NumberFormatException n) {
			errors.add("Please enter a valid number for this fund");
		}

		return errors;
	}

}
